//
// Created by DengLibin on 2018/12/13 0013.
//

/**
 * 容器deque:双端数组
 */
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
//遍历
void showDeque(deque<int> &d)
{
    cout << "deque大小:" << d.size() << endl;
    for (deque<int >::iterator it = d.begin(); it != d.end(); it++)
    {
        cout << *it << " ";
    }
}
void testDeque()
{
    deque<int> d1;
    d1.push_back(1);
    d1.push_back(2);
    d1.push_back(3);
    d1.push_front(-1);
    d1.push_front(-2);
    d1.push_front(-3);
    showDeque(d1);
    cout << "头部元素:" << d1.front() << endl;
    cout << "尾部元素:" << d1.back() << endl;

    //弹出头部元素
    d1.pop_front();
    //弹出尾部元素
    d1.pop_back();
    showDeque(d1);
    cout << "头部元素:" << d1.front() << endl;
    cout << "尾部元素:" << d1.back() << endl;

    //查找元素的下标
    deque<int>::iterator it = find(d1.begin(), d1.end(), 1);
    if (it != d1.end())
    {
        cout << "1的下标是:" << distance(d1.begin(), it) << endl;
    }
    else
    {
        cout << "没找到1这个元素" << endl;
    }

}
int main23()
{
    testDeque();
    return 0;
}